@extends('layouts.app')

@section('title')
    模板消息
@endsection

@section('content')
    <style>
        .table tbody tr td.td-middle{
            vertical-align: middle;
        }
    </style>
    <div id="template">

        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">模板列表 <span style="float: right;">总共有 {{ $templates->total() }} 条模板记录</span></div>

                <div class="panel-body">

                    <form class="form-inline" action="{{ url('admin/operation/template') }}" method="get">
                        <select name="templateId" class="form-control">
                            <option value="">全部</option>
                            @foreach($selects as $templateId => $select)
                            <option value="{{ $templateId }}">{{ $select }}</option>
                            @endforeach
                        </select>
                        <button type="submit" class="btn btn-primary">筛选</button>
                    </form>
                    @if($templates->count() > 0)
                        <table class="table">
                            <thead>
                                <tr>
                                    <th width="5%">id</th>
                                    <td width="5%">接收者</td>
                                    <td width="15%">接收者班级</td>
                                    <td width="5%">模板名称</td>
                                    <td width="25%">发送内容</td>
                                    <td width="15%">发送时间</td>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach($templates as $template)
                                <tr>
                                    <td class="td-middle">{{ $template->id }}</td>
                                    <td class="td-middle">{{ $template->user->name }}</td>
                                    <td class="td-middle">{{ $template->user->class->name }}</td>
                                    <td class="td-middle">{{ \App\Dictionary::template($template->template_id) }}</td>
                                    <td class="td-middle">{!! implode('<br>', json_decode($template->content, true, 0, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP   )) !!}</td>
                                    <td class="td-middle">{{ $template->created_at }}</td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div style="text-align: center;">
                        {{ $templates->appends(['templateId' => $_GET['templateId'] ?? null])->links() }}
                        </div>
                    @endif

                </div>
            </div>
        </div>

    </div>
@endsection

@section('js')
    <script>
        $("select[name='templateId']").val('{{ $_GET['templateId'] ?? null }}');
    </script>
@endsection